﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections.ObjectModel;
using Rotempco.ORM.Generator.Objects;
using Rotempco.ORM.Generator.Logic;

namespace Rotempco.ORM.Generator.ViewModels
{
    public class VMTables
    {
        #region [ Singleton Constructor ]

        static readonly VMTables _Instance = new VMTables();

        static VMTables()
        {
        }

        private VMTables()
        {
            Tables = new ObservableCollection<string>();
            SelectedTables = new ObservableCollection<string>();
        }

        public static VMTables Instance
        {
            get
            {
                return _Instance;
            }
        }

        public static VMTables GetInstance()
        {
            return Instance;
        }

        #endregion

        public ObservableCollection<string> Tables { get; private set; }
        public ObservableCollection<string> SelectedTables { get; private set; }

        public void LoadAll(RotempcoSettings rotempcoSettings)
        {
            Tables.Clear();
            bool useIntegrated = (rotempcoSettings.GetBoolValue("@DatabaseUseIntegrated") == true);
            DatabaseInfoRetrieverLogic.GetTables(
                rotempcoSettings.GetValue("@DatabaseAddress"),
                rotempcoSettings.GetValue("@DatabaseName"),
                useIntegrated,
                rotempcoSettings.GetValue("@DatabaseLogin"),
                rotempcoSettings.GetValue("@DatabasePassword")
                 ).OrderBy(s=>s).ToList().ForEach(s => Tables.Add(s));
           
 

            
        }


        
    }
}
